#include <iostream>

using namespace std;

string ops[1024];
string ads[1024];

bool noterr(string ad)
{
	int port = 0;
	int porti = 1;
	int host = 0;
	int hosti = 1;
	bool portf = true;
	bool hostf = false;
	for (int i = ad.length() - 1;i >= 0;i--)
	{
		if (portf && ad[i] - 48 >= 0 && ad[i] - 48 <= 9)
		{
			port += porti * (int)ad[i];
			porti *= 10;
		}
		if (ad[i] == ':')
		{
			portf = false;
			hostf = true;
		}
		if (hostf && ad[i] - 48 >= 0 && ad[i] - 48 <= 9)
		{
			host += hosti * (int)ad[i];
			hosti *= 10;
		}
		if (ad[i] == '.')
		{
			host = 0;
			hosti = 1;
			if (host > 255 || host < 0)
			{
				return false;
			}
		}
	}
	if (port > 65535 || port < 0)
	{
		return false;
	}
	return true;
}

int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	
	int n;
	string op,ad;
	
	cin >> n;
	
	for (int i = 1;i <= n;i++)
	{
		cin >> op >> ad;
		if (noterr(ad))
		{
			if (op == "Server")
			{
				int f = true;
				for (int j = 1;j <= i;j++)
				{
					if (ads[j] == ad)
					{
						f = false;
					}
				}
				if (f)
				{
					ops[i] = op;
					ads[i] = ad;
					cout << "OK" << endl;
				}
				else
				{
					cout << "FAIL" << endl;
				}
			}
			else if (op == "Client")
			{
				int f = true;
				int j;
				for (j = 1;j <= i;j++)
				{
					if (ads[j] == ad)
					{
						cout << j << endl;
						f = false;
						break;
					}
				}
				if (f)
				{
					cout << "FAIL" << endl;
				}
			}
		}
		else
		{
			cout << "ERR" << endl;
		}
	}
	
	return 0;
}
